<?
	ob_start();
	session_start();
	require_once("drizzo/engine/functions.php");
	drizzo_startup();
	$drizzo_limit = 10;

	$theme_check = $_SERVER['DOCUMENT_ROOT'] . "/drizzo-themes/" . drizzo_theme() . "/index.php";
	if(@file_exists($theme_check)) {
		if(isset($_GET['id'])) {
			$drizzo_post_id = $_GET['id'];
		} else { 
			$uri_vars = drizzo_parse_the_uri();
			$drizzo_offset = $uri_vars['offset'];
			$drizzo_post_id = $uri_vars['post_id'];
			$drizzo_page_type = $uri_vars['page_type'];
		}
		
		if(isset($_GET['path'])) {
			$drizzo_pretty_path = $_GET['path'];
		}
		
		if(!$drizzo_page_type) {
			$drizzo_page_type = "index";
		}
		
		if(is_dir($drizzo_page_type)) {
			exit();
		}

		if($drizzo_post_id && !$_GET['id'] && $drizzo_page_type != 'tags') {
			$post_id_lookup = mysql_query("SELECT `ID`,`type` FROM `$drizzo_posts` WHERE `permalink_name` LIKE '%$drizzo_post_id%'");
			if($post_id_lookup) {
				while($row = mysql_fetch_array($post_id_lookup)) {
					$drizzo_post_id = $row[ID];
					$drizzo_page_type = $row[type];
					if($drizzo_page_type == "page") {
						$template_page_check = drizzo_theme('local_dir') . $uri_vars['page_type'] . ".php";
						if(file_exists($template_page_check)) {
							$drizzo_page_type = $uri_vars['page_type'];
						}
					}
				}
			}
		} elseif ($drizzo_post_id && $_GET['id']) {
			$post_type_lookup = mysql_query("SELECT `type` FROM `$drizzo_posts` WHERE `ID`='$_GET[id]'");
			if($post_type_lookup) {
				$drizzo_page_type = mysql_fetch_array($post_type_lookup);
				$drizzo_page_type = $drizzo_page_type[0];
				if($drizzo_page_type == "page") {
					$template_page_check = drizzo_theme('local_dir') . $uri_vars['page_type'] . ".php";
					if(file_exists($template_page_check)) {
						$drizzo_page_type = $uri_vars['page_type'];
					}
				}
			}
		}		
		
		if($drizzo_page_type) {
			$template_page_check = drizzo_theme('local_dir') . $drizzo_page_type . ".php";
			if(file_exists($template_page_check)) {
				$include_url = drizzo_theme('directory') . $drizzo_page_type . ".php?id=" . $drizzo_post_id . "&path=" . str_replace(' ', '_-_', $_SERVER['REDIRECT_URL']);
			} else {
				$include_url = drizzo_theme('directory') . "blog.php?id=" . $drizzo_post_id . "&path=" . str_replace(' ', '_-_', $_SERVER['REDIRECT_URL']);
			}
			include($include_url);
		}
				
	} else {
		include('basic.php');
	}
?>